/********************************************************/
/*	Copyright (C) 2016 Gong Li Bin		 	*/
/*	Project:	GlbRtbEng-1.0.0			*/
/*	Author:		gong_libin			*/
/*	Date:		2016_06_26			*/
/*	File:		GlbRtbReds.h			*/
/********************************************************/

#ifndef	_GLBRTBREDS_H
#define	_GLBRTBREDS_H

#include "GlbGlobal.h"
#include <hiredis.h>

typedef redisReply			GLBRDREP_S;
typedef redisReply*			GLBRDREP_P;
typedef redisContext			GLBRDCON_S;
typedef redisContext*			GLBRDCON_P;

#define	GLB_RD_RERR(P)			P->err
#define	GLB_RD_RNIL(P)			P = NULL
#define	GLB_RD_RDBS(R)			R->integer
#define	GLB_RD_RTTL(R)			R->elements
#define	GLB_RD_RFRE(C)			redisFree(C)
#define	GLB_RD_RFRO(R)			freeReplyObject(R)
#define	GLB_RD_RCNT(H, P)		redisConnect(H, P)
#define	GLB_RD_RVAL(R, I)		R->element[I]->str
#define	GLB_RD_RLEN(R, I)		R->element[I]->len
#define	GLB_RD_RCMD(C, args...)		redisCommand(C, ##args)

#define	GLB_RD_BGTM			(char*)"start"
#define	GLB_RD_EDTM			(char*)"end"
#define	GLB_RD_BROW			(char*)"browser"
#define	GLB_RD_OSNM			(char*)"os"
#define	GLB_RD_LOCA			(char*)"location"
#define	GLB_RD_MDTY			(char*)"mediatype"
#define	GLB_RD_MEDI			(char*)"media"
#define	GLB_RD_PRIO			(char*)"priority"
#define	GLB_RD_VOLU			(char*)"volume"
#define	GLB_RD_PRIC			(char*)"price"
#define	GLB_RD_CRUL			(char*)"url"
#define	GLB_RD_SCRN			(char*)"screen"
#define	GLB_RD_TYPE			(char*)"type"

inline void* GlbRdScan(GLBRDCON_S* pstCon)
{
	return GLB_RD_RCMD(pstCon, "KEYS *");
}

inline void* GlbRdDbsize(GLBRDCON_S* pstCon)
{
	return GLB_RD_RCMD(pstCon, "DBSIZE");
}

inline void GlbRdFlushdb(GLBRDCON_S* pstCon)
{
	GLB_RD_RCMD(pstCon, "FLUSHDB");

	return;
}

inline void GlbRdFlushAll(GLBRDCON_S* pstCon)
{
	GLB_RD_RCMD(pstCon, "FLUSHALL");

	return;
}

inline void GlbRdSelect(GLBRDCON_S* pstCon, int iDb)
{
	GLB_RD_RCMD(pstCon, "SELECT %d", iDb);

	return;
}

#endif /* _GLBRTBREDS_H */
